<?php
/*------------------------------------------------------------------
Happy Accidents Theme 1.1
by Happy Svensson (http://www.keffkaesque.eu/)
Adapted from original Theme made by SoulSmasher (http://www.soulsmasher.net/)
Thanks to Laura Gonzales, www.networkredux.com, for inspiring me to the name of this Theme!
+--------------------------------------------------------+
| Filename: theme.php
| Author:   Happy Svensson/SoulSmasher
+--------------------------------------------------------+
| This program is released as free software under the
| Affero GPL license. You can redistribute it and/or
| modify it under the terms of this license which you
| can read by viewing the included agpl.txt or online
| at http://www.opensource.org/licenses/agpl-v3.html. 
| Removal of this copyright header is strictly prohibited 
| without written permission from the original author(s).
+--------------------------------------------------------*/
if (!defined("IN_FUSION")) { die("Access Denied"); }
require_once INCLUDES."theme_functions_include.php";

define("THEME_WIDTH", "990");
define("THEME_BULLET", "&middot;");

//v7 sublinks function is a bit more for this, so taken from v6 and tweaked
function thesublinks($sep="&middot;",$class="") {
	$i = 0; $res = "";
	$sres = dbquery("SELECT * FROM ".DB_PREFIX."site_links WHERE link_position>='2' AND ".groupaccess('link_visibility')." AND link_url!='---' ORDER BY link_order ASC");
	if (dbrows($sres)) {
		while($sdata = dbarray($sres)) {
					if ($i != 0) { $res .= " ".$sep."\n"; } else { $res .= "\n"; }
					$link_target = $sdata['link_window'] == "1" ? " target='_blank'" : "";
					$link_class = $class ? " class='$class'" : "";
					if (strstr($sdata['link_url'], "http://") || strstr($sdata['link_url'], "https://")) {
						$res .= "<a href='".$sdata['link_url']."'".$link_target.$link_class.">".$sdata['link_name']."</a>";
					} else {
						$res .= "<a href='".BASEDIR.$sdata['link_url']."'".$link_target.$link_class.">".$sdata['link_name']."</a>";
					}
				
				$i++;
		}
	}
	if ($i != 0) { return $res; } else { return "&nbsp;"; }
}

function render_page($license=false) {
global $settings, $main_style;

//Header
echo "<table cellpadding='0' cellspacing='0' width='".THEME_WIDTH."' align='center'><tr><td>

<table cellpadding='0' cellspacing='0' width='".THEME_WIDTH."' style='border: 0px; margin: 0px auto'>
<tr><td style='width: 5px'>";//5px td is to fit the image
echo "</td><td class='theheader' valign='top'>
<p align='right' style='padding-right:20px;'><font color='#ffffff' size='4'>".stripslashes($settings['siteintro'])."</font><br/></p>";
echo "</td></tr></table>\n";

//sublinks css
	echo "<table width='".THEME_WIDTH."' border='0' cellspacing='0' cellpadding='0'><tr><td>";
	echo "<div id='altlinkler'>";
	echo "<ul><li>".thesublinks("</li>\n<li>");
	echo "</li></ul><div style='clear: both'>&nbsp;</div></div>";
/*if ($settings['siteintro'] != "") {
	echo "</td></tr><tr><td class='welc'><center>".stripslashes($settings['siteintro'])."</center></td></tr></table>";
	} else {*/
	echo "</td></tr></table>";
//}
	
//Content
	echo "<table cellpadding='0' cellspacing='0' width='".THEME_WIDTH."' class='barry'>\n<tr>\n";
	if (LEFT) { echo "<td class='side-border-left' valign='top'>".LEFT."</td>"; }
	echo "<td class='main-bg' valign='top'>".U_CENTER.CONTENT.L_CENTER."</td>";
	if (RIGHT) { echo "<td class='side-border-right' valign='top'>".RIGHT."</td>"; }
	echo "</tr>\n</table>\n";

//Footer
echo "<div id='footer'><table cellpadding='0' cellspacing='0' width='".THEME_WIDTH."' class='footermain'>
<tr>
<td class='footerleft'>".showcopyright()."</td>
<td class='footerright'>
Happy Accidents theme by <a href='http://www.keffkaesque.eu/'>Happy Svensson</a><br/>
</td>
</tr>
</table>
</div>

</td></tr></table>
\n";
}


function render_news($subject, $news, $info) {

	echo "<div class='capmain'>$subject</div>\n";
	echo "<div class='main-body floatfix'>".$news."</div>\n";
	echo "<div class='news-footer'>\n";
	echo newsposter($info,"&middot;").newsopts($info,"&middot;").itemoptions("N",$info['news_id']);
	echo "</div>\n";
}

function render_article($subject, $article, $info) {
	echo "<div class='border tablebreak'>";
	echo "<div class='capmain'>$subject</div>\n";
	echo "<div class='main-body floatfix'>".($info['article_breaks'] == "y" ? nl2br($article) : $article)."</div>\n";
	echo "<div class='news-footer'>\n";
	echo articleposter($info,"&middot;").articleopts($info,"&middot;").itemoptions("A",$info['article_id']);
	echo "</div>\n";
	echo "</div>";
}

function opentable($title) {

echo "<table cellpadding='0' cellspacing='0' width='100%' class='border tablebreak'>
<tr>
<td class='capmain'>$title</td>
</tr>
<tr>
<td class='main-body'>\n";

}

function closetable() {

echo "</td>
</tr>
</table>\n";

}


function openbox($title) {
echo "<table border='1' cellpadding='0' cellspacing='0' class='round'>
  <tr>
    <td></td>
    <td class='rounded-tl'></td>
    <td class='rounded-t'></td>
    <td class='rounded-tr'></td>
    <td></td>
  </tr>
  <tr>
    <td class='rounded-l'></td>
    <td class='rounded-main' colspan='3'>";
}
function closebox() {
	echo "</td>
    <td class='rounded-r'></td>
  </tr>
  <tr>
    <td></td>
    <td class='rounded-bl'></td>
    <td class='rounded-b'></td>
    <td class='rounded-br'></td>
    <td></td>
  </tr>
</table>";
}



function openside($title, $collapse = false, $state = "on") {
	echo "<div class='border tablebreak'>";
	global $panel_collapse; $panel_collapse = $collapse;
	
	echo "<div class='border'>\n";
	echo "<div class='scapmain'>";
	if ($collapse == true) {
		$boxname = str_replace(" ", "", $title);
		echo "<div style='float:right;'>".panelbutton($state,$boxname)."</div>";
	}
	echo $title."</div>\n<div class='side-body floatfix'>\n";
	if ($collapse == true) { echo panelstate($state, $boxname); }

}

function closeside($collapse = false) {

	global $panel_collapse;

	if ($panel_collapse == true) { echo "</div>\n"; }
	echo "</div>\n</div>\n";
	echo "</div>";

}

?>